package com.sense.kukoo.biz_me.view

import androidx.core.widget.addTextChangedListener
import com.alibaba.android.arouter.facade.annotation.Route
import com.sense.feel.common.utils.ToastUtils
import com.sense.kukoo.biz_me.R
import com.sense.kukoo.biz_me.databinding.BizMeActivityFeedbackBinding
import com.sense.kukoo.biz_me.vm.FeedbackViewModel
import com.sense.kukoo.common.constant.ARouterUrl
import com.sense.kukoo.common.mvvm.view.BaseMvvmActivity

@Route(path = ARouterUrl.ROUTE_ME_MODULE_FEEDBACK_ACTIVITY)
class FeedbackActivity : BaseMvvmActivity<FeedbackViewModel, BizMeActivityFeedbackBinding>() {

    private val TAG: String = javaClass.simpleName

    override fun getLayoutId(): Int = R.layout.biz_me_activity_feedback

    override fun getViewModelClass(): Class<FeedbackViewModel> = FeedbackViewModel::class.java

    override fun responseVM(action: Int) {}

    override fun initData() {
        mBinding.lifecycleOwner = this
        mBinding.vm = mViewModel
        mBinding.titleView.init(this)
        setSupportActionBar(mBinding.titleView)
        //
        mViewModel.mSubmitResult.observe(this){
            it?.let {
                mViewModel.mSubmitResult.value = null
                ToastUtils.showToast(getString(com.sense.kukoo.common_i18n.R.string.feedback_submit_success))
                finish()
            }
        }
    }

    override fun initView() {
        //
        mBinding.etDescription.addTextChangedListener(afterTextChanged = {
            mViewModel.checkSubmitData()
        })
        mBinding.etContact.addTextChangedListener(afterTextChanged = {
            mViewModel.checkSubmitData()
        })
    }

    override fun onResume() {
        super.onResume()
        mBinding.etDescription.requestFocus()
    }
}